package com.rtos.model.memory;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import lombok.Data;

/**
 * @Author: biubiu0002
 * @Date: 2021-10-11 19:58
 **/
@Data
public class MATNode {
    private IntegerProperty pid;
    private IntegerProperty address;
    private IntegerProperty endAddress;
    private boolean isFree;
    private boolean isUSer;
    private IntegerProperty size;

    public MATNode(Integer pid, Integer address, Integer endAddress, boolean isFree, boolean isUSer) {
        this.pid = new SimpleIntegerProperty(pid);
        this.address = new SimpleIntegerProperty(address);
        this.endAddress = new SimpleIntegerProperty(endAddress);
        this.isFree = isFree;
        this.isUSer = isUSer;
        this.size = new SimpleIntegerProperty(endAddress - address + 1);
    }

    public int getPID(){
        return pid.getValue();
    }

    public void setPID(Integer pid){
        this.pid.setValue(pid);

    }

    public int getSize(){
        return size.getValue();
    }

    public void setSize(Integer size){
        this.size.setValue(size);

    }

    /**
     * 重写equals方法
     * @param o
     * @return
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        MATNode matNode = (MATNode) o;

        if (isFree != matNode.isFree) return false;
        if (isUSer != matNode.isUSer) return false;
        if (pid != null ? !(pid.get()==matNode.pid.get()) : matNode.pid != null) return false;
        if (address != null ? !(address.get()==matNode.address.get()) : matNode.address != null) return false;
        if (endAddress != null ? !(endAddress.get()==matNode.endAddress.get()) : matNode.endAddress != null) return false;
        return size != null ? size.get()==matNode.size.get() : matNode.size == null;
    }

    @Override
    public int hashCode() {
        int result = pid != null ? pid.hashCode() : 0;
        result = 31 * result + (address != null ? address.hashCode() : 0);
        result = 31 * result + (endAddress != null ? endAddress.hashCode() : 0);
        result = 31 * result + (isFree ? 1 : 0);
        result = 31 * result + (isUSer ? 1 : 0);
        result = 31 * result + (size != null ? size.hashCode() : 0);
        return result;
    }
}